﻿using SRM.Core.Models.Base;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SRM.Application.PageResult.Dtos
{
    public static class PagedList<T>
    {
        public static PagerModel<T> PageList(PagerModelInput input, List<T> list)
        {
            int count = list.Count;
            int num = 1;
            if (count > 1)
            {
                num = (count % input.Pagesize == 0) ? (count / input.Pagesize) : (count / input.Pagesize + 1);
                list = list.Skip((input.PageIndex - 1) * input.Pagesize).Take(input.Pagesize).ToList<T>();
            }
            PagerModel<T> pagerModel = new PagerModel<T>();
            pagerModel.PageIndex = input.PageIndex;
            pagerModel.TotalCount = count;
            pagerModel.PageCount = num;
            pagerModel.Data = list;
            pagerModel.PageStart = ((input.PageIndex - 2 > 0) ? (input.PageIndex - 2) : 1);
            pagerModel.PageEnd = ((input.PageIndex + 2 >= num) ? num : (pagerModel.PageStart + 4));
            return pagerModel;
        }
    }
}
